<template>
  <div class="local-music-container">
    <div class="local-header">
      <h2>本地音乐</h2>
      <div class="actions">
        <el-button type="primary" :icon="FolderAdd" @click="scanMusic">
          扫描音乐
        </el-button>
        <el-button :icon="Upload" @click="importMusic">
          导入音乐
        </el-button>
      </div>
    </div>
    
    <div class="music-stats">
      <el-card>
        <div class="stat-item">
          <div class="stat-number">{{ localSongs.length }}</div>
          <div class="stat-label">本地歌曲</div>
        </div>
      </el-card>
      <el-card>
        <div class="stat-item">
          <div class="stat-number">{{ totalDuration }}</div>
          <div class="stat-label">总时长</div>
        </div>
      </el-card>
      <el-card>
        <div class="stat-item">
          <div class="stat-number">{{ totalSize }}</div>
          <div class="stat-label">总大小</div>
        </div>
      </el-card>
    </div>
    
    <div class="song-list">
      <el-table :data="localSongs" style="width: 100%">
        <el-table-column prop="name" label="歌曲名称" />
        <el-table-column prop="artist" label="歌手" />
        <el-table-column prop="album" label="专辑" />
        <el-table-column prop="duration" label="时长" width="80" />
        <el-table-column prop="size" label="大小" width="100" />
        <el-table-column label="操作" width="120">
          <template #default="scope">
            <el-button size="small" :icon="VideoPlay" circle @click="playSong(scope.row)" />
            <el-button size="small" :icon="Delete" circle @click="deleteSong(scope.row)" />
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { FolderAdd, Upload, VideoPlay, Delete } from '@element-plus/icons-vue'

const localSongs = ref([
  { 
    id: 1, 
    name: '夜曲', 
    artist: '周杰伦', 
    album: '十一月的萧邦', 
    duration: '3:45', 
    size: '8.5MB',
    path: '/music/夜曲.mp3'
  },
  { 
    id: 2, 
    name: '晴天', 
    artist: '周杰伦', 
    album: '叶惠美', 
    duration: '4:30', 
    size: '10.2MB',
    path: '/music/晴天.mp3'
  },
  { 
    id: 3, 
    name: '七里香', 
    artist: '周杰伦', 
    album: '七里香', 
    duration: '4:15', 
    size: '9.8MB',
    path: '/music/七里香.mp3'
  }
])

const totalDuration = computed(() => {
  return '12:30:45' // 模拟总时长
})

const totalSize = computed(() => {
  return '1.2GB' // 模拟总大小
})

const scanMusic = () => {
  console.log('开始扫描本地音乐...')
  // 这里应该调用Electron的API扫描本地文件
}

const importMusic = () => {
  console.log('打开文件选择器...')
  // 这里应该调用Electron的API打开文件选择器
}

const playSong = (song: any) => {
  console.log('播放歌曲:', song.name)
}

const deleteSong = (song: any) => {
  const index = localSongs.value.findIndex(s => s.id === song.id)
  if (index > -1) {
    localSongs.value.splice(index, 1)
  }
}
</script>

<style scoped>
.local-music-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.local-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.local-header h2 {
  margin: 0;
  color: #303133;
}

.music-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.stat-item {
  text-align: center;
  padding: 20px;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  color: #409eff;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.song-list {
  background: white;
  border-radius: 8px;
  overflow: hidden;
}
</style>
